//
//  RoomSmallMap.m
//  Model
//
//  Created by zeb-apple on 2017/6/1.
//  Copyright © 2017年 YDJH. All rights reserved.
//  小地图

#import "RoomSmallMap.h"
#import "RoomMapCell.h"

#define left_rightLayout 5
#define MapWidth 100;


@interface RoomSmallMap ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,strong)UICollectionView *collectionView;

@property (nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation RoomSmallMap

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}
- (void)initView {
    [self addSubview:self.collectionView];
}
#pragma mark - getter
- (UICollectionView *)collectionView {
    if (!_collectionView ) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 100, 66) collectionViewLayout:layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.scrollsToTop = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.backgroundColor = [UIColor redColor];
        [_collectionView registerClass:[RoomMapCell class] forCellWithReuseIdentifier:RoomMapCellID];
    }
    return _collectionView;
}

#pragma mark - Public Method
- (void)reloadData:(NSMutableArray *)dataArray {
    self.dataArray = dataArray;
    [self.collectionView reloadData];
}

#pragma mark - UICollectionViewDelegate/UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return self.dataArray.count;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return [self.dataArray[section] count];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat height = (self.collectionView.frame.size.height - self.dataArray.count*2) / self.dataArray.count ;
    CGFloat width;
    CGFloat roomCount = [self.dataArray[indexPath.section] count];
    
    if (roomCount == 1) {
        width = 100 - 2;
        return CGSizeMake(width ,height);
    }
    else {
        width = (100 - roomCount*2) / roomCount;
        return CGSizeMake(width, height);
    }
}

//设置每组的cell的边界, 具体看下图
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return  UIEdgeInsetsMake(1,1,1,1);
}

//cell的最小行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0.1;
}

//cell的最小列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0.1;
}

- ( UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    RoomMapCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:RoomMapCellID forIndexPath:indexPath];
    
    [cell configureCellWithData:self.dataArray[indexPath.section][indexPath.item] withCallBack:^(NSString *type) {
        
    }];
    return cell;
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
